package manager.dao;

import manager.model.Manager;
import util.JdbcUtil;

import java.util.List;
import java.util.Map;

public class ManagerDaoImpl implements ManagerDao{

    @Override
    public Manager queryByUsernamePassword(String username, String password) {
        String sql = "select id" + " from admin where username = ? and password = ?";
        List<Map<String,Object>> list = JdbcUtil.selectBySql(sql,username,password);
        if (list.isEmpty() || list == null)
            return null;
        Map<String,Object> map = list.get(0);
        Integer id = (Integer)map.get("id");
        Manager manager = new Manager(id,username,password);
        return manager;
    }

    @Override
    public long findNewsNumber(){
        String sql = "select count(*) cou from news";
        List<Map<String,Object>> list = JdbcUtil.selectBySql(sql);
        Map<String,Object> map = list.get(0);
        long count = (long) map.get("cou");
        return count;
    }

    @Override
    public long findUsersNumber() {
        String sql = "select count(*) cou from user";
        List<Map<String,Object>> list = JdbcUtil.selectBySql(sql);
        Map<String,Object> map = list.get(0);
        long count = (long) map.get("cou");
        return count;
    }

    @Override
    public long findPinglunNumber() {
        String sql = "select count(*) cou from pinglun";
        List<Map<String,Object>> list = JdbcUtil.selectBySql(sql);
        Map<String,Object> map = list.get(0);
        long count = (long) map.get("cou");
        return count;
    }

}
